<?php

declare(strict_types=1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\model\WholesaleProduct;
//该文件为自动生成，请按需修改
class WholesaleOrder extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\WholesaleOrder';

    //关联模型
    protected $hasOne = ['user', 'product'];

    protected $append = ['status_text','equity_text'];

    public function index(): string
    {
        return Builder::Table()
            ->autoStructure($this->model, $this->pk, '')
            ->addTopButtons(['export'])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号/系统标识', 'input', '', '\app\common\model\User', 'code|nickname|mobile|tag,id'],
                ['product_id', '缔造商品', 'select', self::getPoductList()],
                ['status', '缔造状态', 'select', $this->model::getOrderStatus('', 2)],
                // ['is_equity', '权益状态', 'select', self::getEquityStatus()],
                ['type', '缔造场次', 'select', self::getType()],
                ['free', '结算状态', 'select', self::getFree()],
            ])
            ->fetch();
    }
    public static function getType()
    {
        return [1 => '上午场', 2 => '下午场'];
    }
    public static function getEquityStatus()
    {
        return [ 1 => '绿色权益', 2 => '红色权益', 3 => '黄色权益'];
    }
    public static function getFree()
    {
        return [1 => '未结算', 2 => '已结算'];
    }
    public static function getPoductList()
    {
        $list = WholesaleProduct::order('id asc')->column('title', 'id');
        return $list;
    }
}
